package com.ruoyi.manage.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.manage.domain.Donation;
import com.ruoyi.manage.domain.vo.DonationVo;
import com.ruoyi.manage.domain.vo.GoodsShelvesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.manage.mapper.GoodsShelvesMapper;
import com.ruoyi.manage.domain.GoodsShelves;
import com.ruoyi.manage.service.IGoodsShelvesService;

/**
 * 货架管理Service业务层处理
 * 
 * @author zzg
 * @date 2025-03-22
 */
@Service
public class GoodsShelvesServiceImpl implements IGoodsShelvesService 
{
    @Autowired
    private GoodsShelvesMapper goodsShelvesMapper;
    @Autowired
    private DonationServiceImpl  donationService;

    /**
     * 查询货架管理
     * 
     * @param id 货架管理主键
     * @return 货架管理
     */
    @Override
    public GoodsShelves selectGoodsShelvesById(Long id)
    {
        return goodsShelvesMapper.selectGoodsShelvesById(id);
    }

    @Override
    public GoodsShelvesVo selectGoodsShelvesVoById(Long id) {
        return goodsShelvesMapper.selectGoodsShelvesVoById(id);
    }

    /**
     * 查询货架管理列表
     * 
     * @param goodsShelves 货架管理
     * @return 货架管理
     */
    @Override
    public List<GoodsShelves> selectGoodsShelvesList(GoodsShelves goodsShelves)
    {
        return goodsShelvesMapper.selectGoodsShelvesList(goodsShelves);
    }

    @Override
    public List<GoodsShelvesVo> selectGoodsShelvesVoList(GoodsShelves goodsShelves) {
        return goodsShelvesMapper.selectGoodsShelvesVoList(goodsShelves);
    }

    /**
     * 新增货架管理
     * 
     * @param goodsShelves 货架管理
     * @return 结果
     */
    @Override
    public int insertGoodsShelves(GoodsShelves goodsShelves)
    {
        goodsShelves.setCreateTime(DateUtils.getNowDate());
        return goodsShelvesMapper.insertGoodsShelves(goodsShelves);
    }

    /**
     * 修改货架管理
     * 
     * @param goodsShelves 货架管理
     * @return 结果
     */
    @Override
    public int updateGoodsShelves(GoodsShelves goodsShelves)
    {
        goodsShelves.setUpdateTime(DateUtils.getNowDate());
        return goodsShelvesMapper.updateGoodsShelves(goodsShelves);
    }

    /**
     * 批量删除货架管理
     * 
     * @param ids 需要删除的货架管理主键
     * @return 结果
     */
    @Override
    public int deleteGoodsShelvesByIds(Long[] ids)
    {
        return goodsShelvesMapper.deleteGoodsShelvesByIds(ids);
    }

    /**
     * 删除货架管理信息
     * 
     * @param id 货架管理主键
     * @return 结果
     */
    @Override
    public int deleteGoodsShelvesById(Long id)
    {
        return goodsShelvesMapper.deleteGoodsShelvesById(id);
    }

    /**
     * 根据设备编号和用户id查询货架信息
     * @param deviceNumber
     * @param id
     * @return
     */
    public List<GoodsShelvesVo> selectGoodsShelvesVoListByPickup(String deviceNumber, Long id,Integer type) {
        Donation donation = Donation.builder().build();
        if(type==0){//待取货
            donation.setReceiverId(id);
            donation.setStatus(6);
        }else if(type==1) {//待入库
            donation.setDonorId(id);
            donation.setStatus(2);
        }else {
            throw new RuntimeException("参数错误");
        }
        List<Donation> list = donationService.selectDonationList(donation);
        if(list.size()==0 || list==null) return new ArrayList<GoodsShelvesVo>();
        List<GoodsShelvesVo> resultList =  goodsShelvesMapper.selectGoodsShelvesVoListByPickup(deviceNumber,list);
        return resultList;
    }
}
